1 module hip.api.graphics.g2d.g2d_binding;
2 public import hip.api.data.commons;
3 public import hip.api.renderer.operations;
4 public import hip.api.graphics.color;
5 public import hip.api.graphics.g2d.animation;
6 public import hip.api.renderer.viewport;
7 public import hip.api.data.font;
8 public import hip.api.data.tilemap;
9 public import hip.api.graphics.text;
10 
11 version(Have_util) version = ImportSpritesheet;
12 
13 version(ImportSpritesheet)
14 {
15     public import hip.util.data_structures : Array2D, Array2D_GC;
16     public alias Spritesheet = Array2D_GC!IHipTextureRegion;
17 }
18 
19 version(DirectCall)
20 {
21     public import hip.graphics.g2d.renderer2d;
22 }
23 else version(ScriptAPI)
24 {
25     void initG2D()
26     {
27         import hip.api.internal;
28         import hip.api.console;
29         loadClassFunctionPointers!HipG2DBinding;
30         log("HipengineAPI: Initialized G2D");
31     }
32 
33     class HipG2DBinding
34     {
35         extern(System) __gshared //All functions there will be loaded
36         {
37             ///Use this only when you're sure you don't need!
38             void function(bool enable = true) setRendererErrorCheckingEnabled;
39 
40             ///Will change the color for the next calls to drawPixel, drawRectangle, drawTriangle, fillRectangle, fillTriangle, drawLine, drawQuadraticBezierLine
41             void function(HipColor color) setGeometryColor;
42             ///Draw a pixel at (x, y) with the color specified at setGeometryColor
43             void function(int x, int y, HipColor color = HipColor.no) drawPixel;
44             ///Draws an unfilled rectangle
45             void function(int x, int y, int w, int h, HipColor color = HipColor.no) drawRectangle;
46             ///Draws an unfilled triangle
47             void function(int x1, int y1, int x2, int y2, int x3, int y3, HipColor color = HipColor.no) drawTriangle;
48             ///Draws a filled rectangle
49             void function(int x, int y, int w, int h, HipColor color = HipColor.no) fillRectangle;
50             ///Draws a filled rectangle with rounded borders
51             void function(int x, int y, int w, int h, int radius = 4, HipColor color = HipColor.no, int precision = 16) fillRoundRect;
52             ///Draws a filled triangle
53             void function(int x1, int y1, int x2, int y2, int x3, int y3, HipColor color = HipColor.no) fillTriangle;
54             ///Draws unfilled circle
55             void function(int x, int y, int radiusW, int radiusH, int degrees = 360, HipColor color = HipColor.no, int precision = 24) drawEllipse;
56             ///Draws a filled circle
57             void function(int x, int y, int radiusW, int radiusH, int degrees = 360, HipColor color = HipColor.no, int precision = 24) fillEllipse;
58             ///Draws a line from (x1, y1) to (x2, y2)
59             void function(int x1, int y1, int x2, int y2, HipColor color = HipColor.no) drawLine;
60             ///Draws a line using bezier points. The higher the precision, the smoother the line, the heavier it is to execute
61             void function(int x0, int y0, int x1, int y1, int x2, int y2, int precision=24, HipColor color = HipColor.no) drawQuadraticBezierLine;
62             ///Draws the target sprite instance
63             void function(IHipTexture texture, ubyte[] vertices) drawSprite;
64             ///Draws a texture at a specified place
65             void function(IHipTexture reg, int x, int y, int z = 0, HipColor = HipColor.white, float scaleX = 1, float scaleY = 1, float rotation = 0) drawTexture;
66             ///Draws a texture region at a specified place
67             void function(IHipTextureRegion reg, int x, int y, int z = 0, HipColor = HipColor.white, float scaleX = 1, float scaleY = 1, float rotation = 0) drawRegion;
68             void function(IHipTilemap reg) drawMap;
69             ///Sets the font for the next drawText commands
70             void function (IHipFont font) setFont;
71             ///Changes textBatch state to use this color
72             void function(HipColor) setTextColor;
73             ///Draws a text using the last font set
74             void function(string text, int x, int y, float scale = 1.0f, HipColor color = HipColor.white, HipTextAlign align_ = HipTextAlign.topCenter, Size bounds = Size.init, bool wordWrap = false) drawText;
75             ///Draw text using those vertices. Low level API
76             void function(void[] vertices, IHipFont font)  drawTextVertices;
77 
78 
79             
80             ///Sets active the viewport passed
81             void function(Viewport v) setViewport;
82             ///Gets the active viewport
83             Viewport function() getCurrentViewport;
84 
85             void function(bool bEnable) setStencilTestingEnabled;
86             void function(uint mask) setStencilTestingMask;
87             void function(ubyte r, ubyte g, ubyte b, ubyte a) setRendererColorMask;
88             void function(HipStencilTestingFunction passFunc, uint reference, uint mask) setStencilTestingFunction;
89             void function(HipStencilOperation stencilFail, HipStencilOperation depthFail, HipStencilOperation stencilAndDephPass) setStencilOperation;
90 
91             ///Width, Height
92             int[2] function() getWindowSize;
93 
94             void function(uint width, uint height) setWindowSize;
95             void function(uint width, uint height) setCameraSize;
96 
97             ///Creates a track for the animation controller
98             IHipAnimationTrack function(string name, uint framesPerSecond, HipAnimationLoopingMode loopingMode = HipAnimationLoopingMode.none) newHipAnimationTrack;
99             ///Creates an animation to be iterated 
100             IHipAnimation function(string name) newHipAnimation;
101 
102 
103             void function(int x = 0, int y = -1) drawGCStats;
104             void function(int x = -1, int y = 0, bool clearTiming = false) drawTimings;
105 
106 
107 
108             version(ImportSpritesheet)
109             {
110                 package Array2D_GC!IHipTextureRegion function(
111                     IHipTexture t,
112                     uint frameWidth, uint frameHeight,
113                     uint width = 0, uint height = 0,
114                     uint offsetX = 0, uint offsetY = 0,
115                     uint offsetXPerFrame = 0, uint offsetYPerFrame = 0
116                 ) cropSpritesheet;
117             }
118 
119         }
120     }
121 
122     version(ImportSpritesheet)
123     Array2D_GC!IHipTextureRegion cropSpritesheetRowsAndColumns(IHipTexture t, uint rows, uint columns)
124     {
125         uint frameWidth = t.getWidth() / columns;
126         uint frameHeight = t.getHeight() / rows;
127         return cropSpritesheet(t,frameWidth,frameHeight, t.getWidth, t.getHeight, 0, 0, 0, 0);
128     }
129     import hip.api.internal;
130     mixin ExpandClassFunctionPointers!HipG2DBinding;
131 }
132 
133 
134 //Code suggestion
135 version(none)
136 {
137     extern(System) __gshared //All functions there will be loaded
138     {
139         ///Use this only when you're sure you don't need!
140         void function(bool enable = true) setRendererErrorCheckingEnabled;
141 
142         ///Will change the color for the next calls to drawPixel, drawRectangle, drawTriangle, fillRectangle, fillTriangle, drawLine, drawQuadraticBezierLine
143         void function(in HipColor color) setGeometryColor;
144         ///Draw a pixel at (x, y) with the color specified at setGeometryColor
145         void function(int x, int y, in HipColor color = HipColor.no) drawPixel;
146         ///Draws an unfilled rectangle
147         void function(int x, int y, int w, int h, in HipColor color = HipColor.no) drawRectangle;
148         ///Draws an unfilled triangle
149         void function(int x1, int y1, int x2, int y2, int x3, int y3, in HipColor color = HipColor.no) drawTriangle;
150         ///Draws a filled rectangle
151         void function(int x, int y, int w, int h, in HipColor color = HipColor.no) fillRectangle;
152         ///Draws a filled rectangle with rounded borders
153         void function(int x, int y, int w, int h, int radius = 4, HipColor color = HipColor.no, int precision = 16) fillRoundRect;
154         ///Draws a filled triangle
155         void function(int x1, int y1, int x2, int y2, int x3, int y3, in HipColor color = HipColor.no) fillTriangle;
156         ///Draws unfilled circle
157         void function(int x, int y, int radiusW, int radiusH, int degrees = 360, in HipColor color = HipColor.no, int precision = 24) drawEllipse;
158         ///Draws a filled circle
159         void function(int x, int y, int radiusW, int radiusH, int degrees = 360, in HipColor color = HipColor.no, int precision = 24) fillEllipse;
160         ///Draws a line from (x1, y1) to (x2, y2)
161         void function(int x1, int y1, int x2, int y2, in HipColor color = HipColor.no) drawLine;
162         ///Draws a line using bezier points. The higher the precision, the smoother the line, the heavier it is to execute
163         void function(int x0, int y0, int x1, int y1, int x2, int y2, int precision=24, in HipColor color = HipColor.no) drawQuadraticBezierLine;
164         ///Draws the target sprite instance
165         void function(IHipTexture texture, ubyte[] vertices) drawSprite;
166         ///Draws a texture at a specified place
167         void function(IHipTexture reg, int x, int y, int z = 0, HipColor = HipColor.white, float scaleX = 1, float scaleY = 1, float rotation = 0) drawTexture;
168         ///Draws a texture region at a specified place
169         void function(IHipTextureRegion reg, int x, int y, int z = 0, HipColor = HipColor.white, float scaleX = 1, float scaleY = 1, float rotation = 0) drawRegion;
170         void function(IHipTilemap reg) drawMap;
171 
172         ///Changes textBatch state to use this color
173         void function(HipColor) setTextColor;
174         ///Sets the font for the next drawText commands
175         package void function (IHipFont font) setFont;
176         ///Draws a text using the last font set
177         void function(string text, int x, int y, float scale = 1.0f, HipColor color = HipColor.white, HipTextAlign align_ = HipTextAlign.topCenter, Size bounds = Size.init, bool wordWrap = false) drawText;
178         ///Draw text using those vertices. Low level API
179         void function(void[] vertices, IHipFont font)  drawTextVertices;
180         
181         ///Sets active the viewport passed
182         void function(Viewport v) setViewport;
183         ///Gets the active viewport
184         Viewport function() getCurrentViewport;
185         void function(bool bEnable) setStencilTestingEnabled;
186         void function(uint mask) setStencilTestingMask;
187         void function(ubyte r, ubyte g, ubyte b, ubyte a) setRendererColorMask;
188         void function(HipStencilTestingFunction passFunc, uint reference, uint mask) setStencilTestingFunction;
189         void function(HipStencilOperation stencilFail, HipStencilOperation depthFail, HipStencilOperation stencilAndDephPass) setStencilOperation;
190 
191         ///Width, Height
192         int[2] function() getWindowSize;
193 
194         void function(uint width, uint height) setWindowSize;
195 
196         void function(uint width, uint height) setCameraSize;
197 
198         ///Creates a track for the animation controller
199         IHipAnimationTrack function(string name, uint framesPerSecond, HipAnimationLoopingMode loopingMode = HipAnimationLoopingMode.none) newHipAnimationTrack;
200         ///Creates an animation to be iterated 
201         IHipAnimation function(string name) newHipAnimation;
202 
203 
204         version(ImportSpritesheet)
205         {
206             package Array2D_GC!IHipTextureRegion function(
207                 IHipTexture t,
208                 uint frameWidth, uint frameHeight,
209                 uint width = 0, uint height = 0,
210                 uint offsetX = 0, uint offsetY = 0,
211                 uint offsetXPerFrame = 0, uint offsetYPerFrame = 0
212             ) cropSpritesheet;
213         }
214 
215     }
216 }